package cn.jobstart.pubInter;

import cn.jobstart.pubInter.exception.DaoException;
import cn.jobstart.pubInter.exception.DaoExceptionEnum;
import cn.jobstart.pubInter.exception.SkException;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* @author sunke
* @Date 2020-12-11 10:20:59
* @description
*/

public abstract class AbstractBaseFindDao<T extends  BaseIdDoMain<KeyType>, TS extends BaseSearch, KeyType> {
    public abstract IBaseFindMapper<T, TS, KeyType> getMapper();

    public T getDetail(KeyType id) throws SkException {
        try {
            return getMapper().getDetail(id);
        } catch (Exception e) {
            e.printStackTrace();
            throw new DaoException(DaoExceptionEnum.DAO_DETAIL_ERROR);
        }
    }

    public List<T> getList(TS search) throws SkException {
        try {
            List<T> ts = getMapper().getList(search);
            return ts;
        } catch (Exception e) {
            e.printStackTrace();
            throw new DaoException(DaoExceptionEnum.DAO_LIST_ERROR);
        }
    }

    public int getListCount(TS search) throws SkException {
        try {
            return getMapper().getListCount(search);
        } catch (Exception e) {
            e.printStackTrace();
            throw new DaoException(DaoExceptionEnum.DAO_LIST_COUNT_ERROR);
        }
    }

    public List<T> getAllList(TS search) throws SkException {
        try {
            return getMapper().getAllList(search);
        } catch (Exception e) {
            e.printStackTrace();
            throw new DaoException(DaoExceptionEnum.DAO_LIST_ERROR);
        }
    }


    /**
     * 查询统计
     *
     * @param fieldSet
     * @param search
     * @return
     * @throws SkException
     */
    public Map<String,Object> totalMap(Set<String> fieldSet, TS search) throws SkException {
        return getMapper().totalMap(fieldSet,search);
    }

    /**
     * 按需查询
     * @param fieldSet
     * @param search
     * @return
     * @throws SkException
     */
   public List<T> getShowFieldList(Set<String> fieldSet, TS search) throws SkException{
       return getMapper().getShowFieldList(fieldSet,search);
   }





}
